<!-- 取消售后 -->
<template>
  <el-dialog
    v-model="dialogVisible"
    title="确认退款"
    width="35%"
    top="30vh"
    class="base_dialog"
    @open="resetForm()"
  >
    <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="退款金额" prop="refundMoney">
        <el-input-number
          v-model.number="form.refundMoney"
          :min="0"
          :precision="2"
          :controls="false"
          controls-position="right"
        />
      </el-form-item>
      <el-form-item v-if="$.isNotEmpty(desc)" label="退改政策">
        <textarea v-model="desc" id="" cols="60" rows="10" disabled></textarea>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="submit()">确定</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import {
  ref,
  reactive,
  computed,
  watch,
  defineProps,
  defineEmits,
  defineExpose,
} from "vue";
import $ from "@util/base";

const props = defineProps({
  money: {
    type: Number,
    default: 0,
  },
  desc: {
    type: String,
    default: "",
  },
});
const emit = defineEmits(["submit"]);
const formRef = ref(null);

const form = reactive({
  refundMoney: null,
});
watch(
  () => props.money,
  (val) => {
    console.log("=============="+val)
    form.refundMoney = val;
  }
);
const desc = computed(() => {
  return props.desc;
});

const dialogVisible = ref(false);

function show() {
  dialogVisible.value = true;
}

defineExpose({ show });

const rules = {
  refundMoney: [
    {
      required: true,
      message: "请输入退款金额",
      trigger: "blur",
    },
  ],
};

function submit() {
  formRef.value.validate((valid) => {
    if (valid) {
      dialogVisible.value = false;
      emit("submit", form.refundMoney);
    }
  });
}

const resetForm = () => {
  formRef.value.resetFields();
};
</script>
